cmake_minimum_required(VERSION 3.20)

set(duilib_VERSION 1.0.0)
project(duilib
	VERSION ${duilib_VERSION}
    DESCRIPTION "Fork 自网易 https://github.com/netease-im/NIM_Duilib_Framework 添加了 cmake 构建规则"
	HOMEPAGE_URL "https://gitee.com/zyf/duilib"
	LANGUAGES CXX)

# 构建 lib 库的规则
add_definitions(-DUNICODE -D_UNICODE)

set(SRC_DIR ${CMAKE_CURRENT_LIST_DIR}/src)
file(GLOB_RECURSE LIB_SRCS  ${SRC_DIR} *.cpp)
add_library(duilib ${LIB_SRCS})

target_include_directories(duilib PUBLIC $<BUILD_INTERFACE:${SRC_DIR}> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

if (BUILD_SHARED_LIBS)
	add_definitions(-DUILIB_EXPORTS)
	set_property(TARGET duilib PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
else()
	add_definitions(-DUILIB_STATIC=1)
	set_property(TARGET duilib PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()

target_link_libraries(duilib comctl32)

include(CMakePackageConfigHelpers)
include(GNUInstallDirs)

# cmake config 配置
configure_package_config_file(cmake/config.cmake.in
	${CMAKE_CURRENT_BINARY_DIR}/duilib-config.cmake
	INSTALL_DESTINATION ${CMAKE_INSTALL_DATADIR}/duilib
	NO_SET_AND_CHECK_MACRO)
write_basic_package_version_file(
	${CMAKE_CURRENT_BINARY_DIR}/duilib-config-version.cmake
	VERSION ${duilib_VERSION}
	COMPATIBILITY SameMajorVersion)

# 安装规则
install(
	FILES ${CMAKE_CURRENT_BINARY_DIR}/duilib-config.cmake
          ${CMAKE_CURRENT_BINARY_DIR}/duilib-config-version.cmake
	DESTINATION ${CMAKE_INSTALL_DATADIR}/duilib)

install(TARGETS duilib EXPORT duilib-targets)
install(DIRECTORY ${SRC_DIR}/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/duilib FILES_MATCHING
	PATTERN "*.h"
	PATTERN "*.tlh")
install(FILES ${SRC_DIR}/Utils/Flash11.tlb DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(EXPORT duilib-targets
	NAMESPACE duilib::
	DESTINATION ${CMAKE_INSTALL_DATADIR}/duilib)
